import Cookie from 'vue-cookies'
export default async () => {
  const langStore = useLanguageStore()
  const { data } = await http.get('/sys/config/lang')
  const { name, language, langItemList } = data
  let langName = ''
  const langList = langItemList.filter(f => !f.hide)
  const curLanguage = Cookie.get('bbcLanguage')
  let isExist = false
  if (curLanguage) {
    for (const lang of langList) {
      if (lang.language === curLanguage) {
        langName = lang.name
        isExist = true
        break
      }
    }
  }
  // 当前无缓存语言或当前缓存语言不在语言列表时
  if (!curLanguage || !isExist) {
    langName = name
    langStore.SET_LANGUAGE(language)
  }
  langStore.SET_LANG_INFO({ langList, langName })
}
